
 /**
 * @file tal_error_code.h
 * @brief Common process - error code
 * @version 1.0.0
 * @date 2021-09-09
 *
 * @copyright Copyright 2018-2021 Tuya Inc. All Rights Reserved.
 *
 */
#ifndef __TAL_ERROR_CODE_H__
#define __TAL_ERROR_CODE_H__


#ifdef __cplusplus
    extern "C" {
#endif

#include "tuya_cloud_types.h"

/**
 * @enum tuya error code storage type
 */
typedef enum {
    TAL_ERROR_CODE_USE_FLASH = 0,
    TAL_ERROR_CODE_USE_RAM
} TAL_ERR_CODE_STORE_E;

/**
 * @enum keep track of important things, 1-15 is used by sdk
 */
typedef enum {
    TAL_ERROR_CODE_ABNORMAL_RESET   = 16,  ///< device reset
    TAL_ERROR_CODE_PARENT_LOST      = 17,  ///< device parent lost
    TAL_ERROR_CODE_NWK_LEAVE_SELF   = 18,  ///< device leave network by itself
    TAL_ERROR_CODE_NWK_LEAVE_GW     = 19,  ///< device leave network by remote command, such as gateway or it's parent
    TAL_ERROR_CODE_IO_ERROR         = 20,  ///< GPIO input or output error
    TAL_ERROR_CODE_MEM_ASSERT       = 21,  ///< memory assert error
    TAL_ERROR_CODE_ADDR_CHANGE      = 22,  ///< addr change
    TAL_ERROR_CODE_RESET_LEAVE      = 23,  ///< recv ZCL_RESET_TO_FACTORY_DEFAULTS_COMMAND_ID
    TAL_ERROR_CODE_RESET_NO_LEAVE   = 24,  ///< recv basic cluster cmd 0xF0(private cmd)
    TAL_ERROR_CODE_WAKUP_TIMEOUT    = 25,  ///< a sleep device is always wakeup.
    TAL_ERROR_CODE_RESET_LEAVE_INVALID = 26, ///< recv ZCL_RESET_TO_FACTORY_DEFAULTS_COMMAND_ID with invalid arguments.
    TAL_ERROR_CODE_NWK_RECOVERY_FAILED = 27, ///< network self recovery failed due to the original SDK.
    TAL_ERROR_CODE_GROUP_OTA_TIMEOUT = 28, ///< group ota timeout event occur.
	TAL_ERROR_CODE_IDLE             = 0xFF,///< idle state
} TAL_ERR_CODE_E;


typedef struct {
    UINT_T utc_time;
    UINT8_T err_code;
} TAL_ERR_ITEM_T;

typedef struct {
    TAL_ERR_CODE_STORE_E type;
    UINT8_T max_num;
    UINT_T period;              ///< error code period(bat:ms)
} TAL_ERR_CODE_T;

BOOL_T tal_error_code_set(TAL_ERR_CODE_E err_code);
VOID_T tal_error_code_period_set(UINT_T time_ms);
VOID_T tal_error_code_storage_type_set(TAL_ERR_CODE_STORE_E type);

#ifdef __cplusplus
}
#endif

#endif

